package com.lf.controller;

import com.lf.model.EbOrder;
import com.lf.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/list")
    public ModelAndView list(@RequestParam(value = "page", defaultValue = "1") int page,
                             @RequestParam(value = "pageSize", defaultValue = "3") int pageSize) {
        //1.获取新闻表的第1页数据，每页3条
        List<EbOrder> orders = orderService.list(page, pageSize);
        int maxPage = orderService.getMaxPage(pageSize);
        //2.将数据(list)和视图(jsp)返回给spring mvc中央控制
        ModelAndView mv = new ModelAndView();
        //绑定数据
        mv.addObject("orders", orders);//key-value
        mv.addObject("curPage", page);

        mv.addObject("maxPage",maxPage);
        //绑定视图
        mv.setViewName("manage/order");
        return mv;
    }
}
